/*
 * Scope.java
 *
 * Created on 2008/06/08 +0900
 *
 * $Revision: 58 $
 * $Date: 2008-12-06 08:59:45 +0000 (Sat, 06 Dec 2008) $
 */

package org.gikolet.framework.inject;

/**
 * @author Tetsutaro (latest modification by $Author: tetsutaro.ss $)
 * @version $Revision: 58 $ $Date: 2008-12-06 08:59:45 +0000 (Sat, 06 Dec 2008) $
 */
public interface Scope {
    Scope PROTOTYPE = new Scope() {
	public Provider scope(String key, final Provider unscoped) {
	    return new Provider() {
		public Object get() {
		    return unscoped.get();
		}
	    };
	}
    };

    Scope SINGLETON = new Scope() {
	public Provider scope(String key, final Provider unscoped) {
	    return new Provider() {
		private Object instance;

		public Object get() {
		    synchronized (Injector.class) {
			if (this.instance == null) {
			    this.instance = unscoped.get();
			}
		    }
		    return this.instance;
		}
	    };
	}
    };

    Scope EAGER_SINGLETON = new Scope() {
	public Provider scope(String key, final Provider unscoped) {
	    return new Provider() {
		private Object instance = unscoped.get();

		public Object get() {
		    return this.instance;
		}
	    };
	}
    };

    Provider scope(String key, final Provider unscoped);
}
